mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
hotfix/fix-technical-output: Include Dates in Output (#5754)
* fixes output to include dates * ichimoku * add trading_periods param to cones * add param to integration tests --------- Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
This commit is contained in:
@@ -889,6 +889,7 @@ def test_technical_cg(params, data_type):
|
||||
"upper_q": "",
|
||||
"model": "",
|
||||
"is_crypto": "",
|
||||
"trading_periods": "",
|
||||
},
|
||||
"equity",
|
||||
),
|
||||
@@ -899,7 +900,8 @@ def test_technical_cg(params, data_type):
|
||||
"lower_q": "0.3",
|
||||
"upper_q": "0.7",
|
||||
"model": "Parkinson",
|
||||
"is_crypto": "true",
|
||||
"is_crypto": "True",
|
||||
"trading_periods": "",
|
||||
},
|
||||
"crypto",
|
||||
),
|
||||
|
||||
@@ -832,6 +832,7 @@ def test_technical_cg(params, data_type, obb):
|
||||
"upper_q": "",
|
||||
"model": "",
|
||||
"is_crypto": "",
|
||||
"trading_periods": "",
|
||||
},
|
||||
"stocks",
|
||||
),
|
||||
@@ -842,7 +843,8 @@ def test_technical_cg(params, data_type, obb):
|
||||
"lower_q": "0.3",
|
||||
"upper_q": "0.7",
|
||||
"model": "Parkinson",
|
||||
"is_crypto": "true",
|
||||
"is_crypto": "True",
|
||||
"trading_periods": "",
|
||||
},
|
||||
"crypto",
|
||||
),
|
||||
|
||||
@@ -378,6 +378,7 @@ def calculate_cones(
|
||||
"Rogers-Satchell",
|
||||
"Yang-Zhang",
|
||||
],
|
||||
trading_periods: Optional[int] = None,
|
||||
) -> pd.DataFrame:
|
||||
"""Calculate Cones."""
|
||||
estimator = pd.DataFrame()
|
||||
@@ -412,7 +413,10 @@ def calculate_cones(
|
||||
|
||||
for window in windows:
|
||||
estimator = model_functions[model]( # type: ignore
|
||||
window=window, data=data, is_crypto=is_crypto
|
||||
window=window,
|
||||
data=data,
|
||||
is_crypto=is_crypto,
|
||||
trading_periods=trading_periods,
|
||||
)
|
||||
|
||||
if estimator.empty:
|
||||
|
||||
@@ -69,7 +69,8 @@ def atr(
|
||||
df_target.ta.atr(length=length, mamode=mamode, drift=drift, offset=offset)
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(df_atr, how="left"), index=True)
|
||||
output = pd.concat([df, df_atr], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -174,7 +175,8 @@ def obv(
|
||||
df_target = get_target_columns(df, ["close", "volume"])
|
||||
df_obv = pd.DataFrame(df_target.ta.obv(offset=offset))
|
||||
|
||||
results = df_to_basemodel(df_target.join(df_obv, how="left"), index=True)
|
||||
output = pd.concat([df, df_obv], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -220,7 +222,8 @@ def fisher(
|
||||
df_target = get_target_columns(df, ["high", "low"])
|
||||
df_fisher = pd.DataFrame(df_target.ta.fisher(length=length, signal=signal))
|
||||
|
||||
results = df_to_basemodel(df_target.join(df_fisher, how="left"), index=True)
|
||||
output = pd.concat([df, df_fisher], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -269,7 +272,8 @@ def adosc(
|
||||
df_target = get_target_columns(df, ["high", "low", "close", "volume", "open"])
|
||||
df_adosc = pd.DataFrame(df_target.ta.adosc(fast=fast, slow=slow, offset=offset))
|
||||
|
||||
results = df_to_basemodel(df_target.join(df_adosc, how="left"), index=True)
|
||||
output = pd.concat([df, df_adosc], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -342,7 +346,8 @@ def bbands(
|
||||
)
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(bbands_df, how="left"), index=True)
|
||||
output = pd.concat([df, bbands_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -399,7 +404,8 @@ def zlma(
|
||||
)
|
||||
).dropna()
|
||||
|
||||
results = df_to_basemodel(df_target.join(zlma_df, how="left"), index=True)
|
||||
output = pd.concat([df, zlma_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -451,7 +457,8 @@ def aroon(
|
||||
df_target = get_target_columns(df, ["high", "low", "close"])
|
||||
aroon_df = pd.DataFrame(df_target.ta.aroon(length=length, scalar=scalar)).dropna()
|
||||
|
||||
results = df_to_basemodel(df_target.join(aroon_df, how="left"), index=True)
|
||||
output = pd.concat([df, aroon_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -509,7 +516,8 @@ def sma(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(sma_df, how="left"), index=True)
|
||||
output = pd.concat([df, sma_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -602,7 +610,8 @@ def vwap(
|
||||
df_target = get_target_columns(df, ["high", "low", "close", "volume"])
|
||||
df_vwap = pd.DataFrame(df_target.ta.vwap(anchor=anchor, offset=offset).dropna())
|
||||
|
||||
results = df_to_basemodel(df_target.join(df_vwap, how="left"), index=True)
|
||||
output = pd.concat([df, df_vwap], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -664,8 +673,8 @@ def macd(
|
||||
prefix=target,
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(macd_df, how="left"), index=True)
|
||||
output = pd.concat([df, macd_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -720,7 +729,8 @@ def hma(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(hma_df, how="left"), index=True)
|
||||
output = pd.concat([df, hma_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -773,7 +783,8 @@ def donchian(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(donchian_df, how="left"), index=True)
|
||||
output = pd.concat([df, donchian_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -823,10 +834,10 @@ def ichimoku(
|
||||
lookahead=lookahead,
|
||||
)
|
||||
|
||||
df_result = df_target.join(df_span.add_prefix("span_"), how="left")
|
||||
df_result = df.join(df_span.add_prefix("span_"), how="left")
|
||||
df_result = df_result.join(df_ichimoku, how="left")
|
||||
|
||||
results = df_to_basemodel(df_result, index=True)
|
||||
results = df_to_basemodel(df_result.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -876,7 +887,8 @@ def clenow(
|
||||
orient="index",
|
||||
).transpose()
|
||||
|
||||
results = df_to_basemodel(df_clenow)
|
||||
output = pd.concat([df, df_clenow], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -921,7 +933,8 @@ def ad(data: List[Data], index: str = "date", offset: int = 0) -> OBBject[List[D
|
||||
df_target = get_target_columns(df, ["high", "low", "close", "volume"])
|
||||
ad_df = pd.DataFrame(df_target.ta.ad(offset=offset).dropna())
|
||||
|
||||
results = df_to_basemodel(df_target.join(ad_df, how="left"), index=True)
|
||||
output = pd.concat([df, ad_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -970,7 +983,8 @@ def adx(
|
||||
df_target.ta.adx(length=length, scalar=scalar, drift=drift).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(adx_df, how="left"), index=True)
|
||||
output = pd.concat([df, adx_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1025,7 +1039,8 @@ def wma(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(wma_df, how="left"), index=True)
|
||||
output = pd.concat([df, wma_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1065,7 +1080,8 @@ def cci(
|
||||
df_target = get_target_columns(df, ["close", "high", "low"])
|
||||
cci_df = pd.DataFrame(df_target.ta.cci(length=length, scalar=scalar).dropna())
|
||||
|
||||
results = df_to_basemodel(df_target.join(cci_df, how="left"), index=True)
|
||||
output = pd.concat([df, cci_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1125,7 +1141,8 @@ def rsi(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(rsi_df, how="left"), index=True)
|
||||
output = pd.concat([df, rsi_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1181,7 +1198,8 @@ def stoch(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(stoch_df, how="left"), index=True)
|
||||
output = pd.concat([df, stoch_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1239,8 +1257,8 @@ def kc(
|
||||
offset=offset,
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(kc_df, how="left"), index=True)
|
||||
output = pd.concat([df, kc_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1281,7 +1299,8 @@ def cg(
|
||||
df_target = get_target_columns(df, ["high", "low", "close"])
|
||||
cg_df = pd.DataFrame(df_target.ta.cg(length=length).dropna())
|
||||
|
||||
results = df_to_basemodel(df_target.join(cg_df, how="left"), index=True)
|
||||
output = pd.concat([df, cg_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
@@ -1301,6 +1320,7 @@ def cones(
|
||||
"Yang-Zhang",
|
||||
] = "STD",
|
||||
is_crypto: bool = False,
|
||||
trading_periods: Optional[int] = None,
|
||||
) -> OBBject[List[Data]]:
|
||||
"""Calculate the realized volatility quantiles over rolling windows of time.
|
||||
|
||||
@@ -1340,7 +1360,8 @@ def cones(
|
||||
It is a weighted average of the Rogers-Satchell volatility and the open-to-close volatility.
|
||||
is_crypto : bool, optional
|
||||
Whether the data is crypto or not. If True, volatility is calculated for 365 days instead of 252
|
||||
|
||||
trading_periods : Optional[int] [default: 252]
|
||||
Number of trading periods in a year.
|
||||
Returns
|
||||
-------
|
||||
OBBject[List[Data]]
|
||||
@@ -1357,7 +1378,12 @@ def cones(
|
||||
|
||||
df = basemodel_to_df(data, index=index)
|
||||
df_cones = helpers.calculate_cones(
|
||||
data=df, lower_q=lower_q, upper_q=upper_q, model=model, is_crypto=is_crypto
|
||||
data=df,
|
||||
lower_q=lower_q,
|
||||
upper_q=upper_q,
|
||||
model=model,
|
||||
is_crypto=is_crypto,
|
||||
trading_periods=trading_periods,
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_cones)
|
||||
@@ -1413,6 +1439,7 @@ def ema(
|
||||
).dropna()
|
||||
)
|
||||
|
||||
results = df_to_basemodel(df_target.join(ema_df, how="left"), index=True)
|
||||
output = pd.concat([df, ema_df], axis=1)
|
||||
results = df_to_basemodel(output.reset_index())
|
||||
|
||||
return OBBject(results=results)
|
||||
|
||||
Reference in New Issue
Block a user