Skip to content

Commit

Permalink
Added extra plot on app example
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedamen committed May 6, 2021
1 parent 51c59a1 commit 54e2077
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ In chartpy/examples you will find several demos

* 06 May 2021
* Fixed subplots with plotly
* Added realized vol to dashboard example
* 05 May 2021
* Add simple dashboard example for downloading Quandl data
* 04 May 2021
Expand Down
20 changes: 15 additions & 5 deletions chartpy_examples/dashboard_examples/layoutchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import pandas as pd
import datetime
import math

import quandl

Expand All @@ -37,7 +38,8 @@ def __init__(self, app=None, constants=None, quandl_api_key=None):
def attach_callbacks(self):

output = self._callback_manager.output_callback(self.page_id(),
['quandl-fig',
['spot-fig',
'vol-fig',
'msg-status'])
input = self._callback_manager.input_callback(self.page_id(), 'calculate-button')
state = self._callback_manager.state_callback(self.page_id(), ['ticker-val'])
Expand All @@ -53,9 +55,17 @@ def calculate_button(self, *args):
try:
df = pd.DataFrame(quandl.get(ticker))

return Chart(engine="plotly").plot(df,
style=Style(plotly_plot_mode='dash', width=980, height=480, scale_factor=-1)), \
"Plotted " + ticker + " at " + datetime.datetime.utcnow().strftime("%b %d %Y %H:%M:%S")
df_vol = (df / df.shift(1)).rolling(window=20).std()* math.sqrt(252) * 100.0

spot_fig = Chart(engine="plotly").plot(df,
style=Style(title='Spot', plotly_plot_mode='dash', width=980, height=480, scale_factor=-1))

vol_fig = Chart(engine="plotly").plot(df_vol,
style=Style(title='Realized Vol 1M', plotly_plot_mode='dash', width=980,
height=480, scale_factor=-1))
msg = "Plotted " + ticker + " at " + datetime.datetime.utcnow().strftime("%b %d %Y %H:%M:%S")

return spot_fig, vol_fig, msg
except Exception as e:
print(str(e))
pass
Expand Down Expand Up @@ -90,7 +100,7 @@ def construct_layout(self):

self._sc.horizontal_bar(),

self._sc.plot("Quandl Plot", id=['quandl-fig'], prefix_id=self.page_id(), height=500),
self._sc.plot("Quandl Plot", id=['spot-fig', 'vol-fig'], prefix_id=self.page_id(), height=500),
]
)

0 comments on commit 54e2077

Please sign in to comment.