Skip to content

Commit

Permalink
Merge pull request #10 from Cuttlas90/performance-fund-chart
Browse files Browse the repository at this point in the history
add performance chart
  • Loading branch information
Cuttlas90 committed Jul 14, 2024
2 parents a2e3160 + cf6f498 commit 84a7ee8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
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

0 comments on commit 84a7ee8

Please sign in to comment.