@@ -15,10 +15,6 @@ def _(mo):
1515@app .cell
1616def _ ():
1717 import marimo as mo
18-
19- app = mo .App (
20- requirements = ["quantflow" ]
21- )
2218 return (mo ,)
2319
2420
@@ -55,11 +51,15 @@ def _(mo):
5551def _ (data , period ):
5652 from quantflow .ta .supersmoother import SuperSmoother
5753 from quantflow .ta .ewma import EWMA
54+ # create the filters
5855 smoother = SuperSmoother (period = period .value )
5956 ewma = EWMA (period = period .value )
60- sm = data [["date" , "close" ]].copy ()
61- sm ["supersmoother" ] = data ["close" ].apply (smoother .update )
62- sm ["ewma" ] = data ["close" ].apply (ewma .update )
57+ ewma_min = EWMA (period = period .value , tau = 0.5 )
58+ # sort dates ascending
59+ sm = data [["date" , "close" ]].copy ().sort_values ("date" , ascending = True ).reset_index (drop = True )
60+ sm ["supersmoother" ] = sm ["close" ].apply (smoother .update )
61+ sm ["ewma" ] = sm ["close" ].apply (ewma .update )
62+ sm ["ewma_min" ] = sm ["close" ].apply (ewma_min .update )
6363 return (sm ,)
6464
6565
@@ -68,7 +68,7 @@ def _(alt, sm):
6868 # Melt the dataframe to a long format suitable for Altair
6969 sm_long = sm .melt (
7070 id_vars = ['date' ],
71- value_vars = ['close' , 'supersmoother' , "ewma" ],
71+ value_vars = ['close' , 'supersmoother' , "ewma" , "ewma_min" ],
7272 var_name = 'Signal' ,
7373 value_name = 'Price'
7474 )
@@ -79,8 +79,8 @@ def _(alt, sm):
7979 y = alt .Y ('Price:Q' , title = 'Price (USD)' , scale = alt .Scale (zero = False )),
8080 color = alt .Color ('Signal:N' , title = 'Signal' ,
8181 scale = alt .Scale (
82- domain = ['close' , 'supersmoother' , 'ewma' ],
83- range = ['#4c78a8' , '#f58518' , '#e45756' ]) # Vega-Lite default palette
82+ domain = ['close' , 'supersmoother' , 'ewma' , "ewma_min" ],
83+ range = ['#4c78a8' , '#f58518' , '#e45756' , '#e45756' ]) # Vega-Lite default palette
8484 ),
8585 tooltip = [
8686 alt .Tooltip ('date:T' , title = 'Date' ),
0 commit comments