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

SFX warmup issue of ma_std_dev #154

Open
femtotrader opened this issue Jul 9, 2024 · 0 comments
Open

SFX warmup issue of ma_std_dev #154

femtotrader opened this issue Jul 9, 2024 · 0 comments

Comments

@femtotrader
Copy link
Contributor

femtotrader commented Jul 9, 2024

Hello,

I think SFX have a warmup issue (on ma_std_dev)

See data

Date,Open,High,Low,Close,Volume,atr,std_dev,ma_std_dev
02/22/2013 12:00:00 AM,151.16,151.89,150.49,151.89,106292600,,,
02/25/2013 12:00:00 AM,152.63,152.86,149.0,149.0,245483200,,,
02/26/2013 12:00:00 AM,149.72,150.2,148.73,150.02,186331600,,,
02/27/2013 12:00:00 AM,149.89,152.33,149.76,151.91,143932600,,,
02/28/2013 12:00:00 AM,151.9,152.87,151.41,151.61,123724200,,,
03/01/2013 12:00:00 AM,151.09,152.34,150.41,152.11,170612700,,,
03/04/2013 12:00:00 AM,151.76,152.92,151.52,152.92,97328800,,,
03/05/2013 12:00:00 AM,153.66,154.7,153.64,154.29,121238200,,,
03/06/2013 12:00:00 AM,154.84,154.92,154.16,154.5,94284300,,,
03/07/2013 12:00:00 AM,154.71,154.98,154.52,154.78,86002000,,,
03/08/2013 12:00:00 AM,155.46,155.65,154.66,155.44,122805700,,,
03/11/2013 12:00:00 AM,155.33,156.04,155.13,156.03,83235500,1.5841666666666658,2.0828806174782697,
03/12/2013 12:00:00 AM,155.92,156.1,155.21,155.68,104108300,1.5263194444444423,2.1939593521505545,
03/13/2013 12:00:00 AM,155.76,156.12,155.23,155.9,91051500,1.4732928240740735,1.90548532021518,9992.0607750966146683
03/14/2013 12:00:00 AM,156.31,156.8,156.22,156.73,123614200,1.4255184220679011,1.6973876987889336,1.9322774570515562
03/15/2013 12:00:00 AM,155.85,156.04,155.31,155.83,133153200,1.4250585535622415,1.5738955563258366,1.7255895251099835
03/18/2013 12:00:00 AM,154.34,155.64,154.2,154.97,126518300,1.4421370074320568,1.27914576530155,1.5168096734721068
03/19/2013 12:00:00 AM,155.3,155.51,153.59,154.61,167049900,1.4819589234793842,0.9684781876738394,1.273839836433742
03/20/2013 12:00:00 AM,155.52,155.95,155.26,155.69,113607800,1.4701290131894336,0.7065226858038988,0.9847155462597628

9992.0607750966146683 looks odd here (compared to ma_std values which where 2.0828806174782697, 2.1939593521505545, 1.90548532021518

Data https://github.com/QuantConnect/Lean/blob/master/Tests/TestData/spy_ppo.txt

Code to reproduce

import pandas as pd
from pathlib import Path
import talipp
from talipp.ohlcv import OHLCVFactory
from talipp.indicators import SFX

def main():
    fname = "spy_ppo.txt"
    datetime_fmt = "%m/%d/%Y %I:%M:%S %p"

    df = pd.read_csv(fname)
    df["Date"] = pd.to_datetime(df["Date"], format=datetime_fmt)
    df = df.set_index("Date")

   def generate_reference_data_for_mimo_indicator(
        indicator_type, parameters, output_names, fname_stem
    ):
        df_in = df[["Open", "High", "Low", "Close", "Volume"]]
        input_values = OHLCVFactory.from_dict(
            {
                "open": df.Open,
                "high": df.High,
                "low": df.Low,
                "close": df.Close,
                "volume": df.Volume,
            }
        )
        indicator = indicator_type(**parameters, input_values=input_values)
        output_values = {output_name: [] for output_name in output_names}
        raw_output_values = list(indicator)
        for raw_output_value in raw_output_values:
            if raw_output_value is None:
                for output_name in output_names:
                    output_value_for_name = np.nan
                    output_values[output_name].append(output_value_for_name)
            else:
                for output_name in output_names:
                    output_value_for_name = getattr(raw_output_value, output_name)
                    output_values[output_name].append(output_value_for_name)
        df_out = pd.concat([df_in, pd.DataFrame(output_values, index=df.index)], axis=1)
        df_out.index = df_out.index.strftime(datetime_fmt)
        df_out.to_csv(Path("out") / f"{fname_stem}.csv")

    generate_reference_data_for_mimo_indicator(
        SFX,
        {"atr_period": 12, "std_dev_period": 12, "std_dev_smoothing_period": 3},
        ["atr", "std_dev", "ma_std_dev"],
        "spy_with_sfx",
    )

if __name__ == "__main__":
    main()

Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant