Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add performance chart #10

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions funds/fund.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ def update_fund_data(self):

response = requests.get(self.fund_address+"/Chart/TotalNAV?type=getnavtotal", timeout=60)
json_object = json.loads(response.text)
self.performance = []
self.performance = {}
if len(json_object[2]['List']) >= 7:
self.performance.append((json_object[2]['List'][6]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"])
self.performance["هفتگی"]=(json_object[2]['List'][6]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"]
else:
self.performance.append(0)
self.performance["هفتگی"]=0
if len(json_object[2]['List']) >= 23:
self.performance.append((json_object[2]['List'][22]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"])
self.performance["ماهانه"]=(json_object[2]['List'][22]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"]
else:
self.performance.append(0)
self.performance["ماهانه"]=0
if len(json_object[2]['List']) >= 67:
self.performance.append((json_object[2]['List'][66]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"])
self.performance["فصلی"]=(json_object[2]['List'][66]["y"]-json_object[2]['List'][0]["y"])/json_object[2]['List'][0]["y"]
else:
self.performance.append(0)
self.performance["فصلی"]=0
def update_closing_price(self):

url = "https://cdn.tsetmc.com/api/ClosingPrice/GetClosingPriceInfo/{}".format(self.code)
Expand Down
31 changes: 23 additions & 8 deletions pages/leveraged_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,26 @@
chart_product = alt.layer(chart, labels).resolve_scale(color='independent')
st.altair_chart(chart_product, use_container_width=True)

# with col2:
# st.header('میزان دارایی نقد و اوراق', divider='rainbow')
# chart = alt.Chart(funds_df).mark_bar().encode(
# alt.X('name:N', title='نام صندوق'),
# alt.Y('performance:Q', title="میزان دارایی نقد و اوراق").axis(format='%'),
# alt.Color('name:N', title='نام صندوق'),
# )
# st.altair_chart(chart, use_container_width=True)
with col2:
d = []
for index, row in funds_df.iterrows():
for key, value in row["performance"].items():
d.append({
"fund": row["name"],
"time": key,
"perfor": value
})
performance_df = pd.DataFrame(d)
st.header('عملکرد صندوقها', divider='rainbow')
chart = alt.Chart(performance_df).mark_bar().encode(
alt.X('time:N', title='زمان', axis=alt.Axis(labelAngle=0)),
alt.Y('perfor:Q', title="میزان دارایی نقد و اوراق",axis=alt.Axis(grid=False)).axis(format='%'),
alt.Color('fund:N', title='نام صندوق'),
alt.XOffset('fund:N', title='نام صندوق'),
tooltip=[alt.Tooltip("perfor:Q", format=",.2%", title='عملکرد'), alt.Tooltip("fund:N", title='صندوق'),]
)

chart_product = alt.layer(chart).resolve_scale(color='independent')
st.altair_chart(chart_product, use_container_width=True)

# InvalidHeader
Loading