diff --git a/RAI_Digital_Twin_Intro_Challenges/zcstarr/behavioral_shift_with_csi_divergence.html b/RAI_Digital_Twin_Intro_Challenges/zcstarr/behavioral_shift_with_csi_divergence.html new file mode 100644 index 0000000..ff8e1f3 --- /dev/null +++ b/RAI_Digital_Twin_Intro_Challenges/zcstarr/behavioral_shift_with_csi_divergence.html @@ -0,0 +1,15332 @@ + + +
+ + +The Digital Twin(DT) Execution Report shows the results of a DT execution.
+ +%load_ext autotime
+time: 353 µs (started: 2021-12-02 17:27:02 -08:00) ++
import pandas as pd
+import plotly.express as px
+import json
+import os
+import plotly.offline as pyo
+pyo.init_notebook_mode()
+time: 1.91 s (started: 2021-12-02 17:27:03 -08:00) ++
base_path = "../../data/runs/2021-06-09 16:49:23.697639-"
+time: 559 µs (started: 2021-12-02 17:27:06 -08:00) ++
# Parameters
+base_path = "/Users/zcstarr/src/token_engineering/reflexer-digital-twin/data/runs/2021-12-03 01:25:59.179791-"
+time: 689 µs (started: 2021-12-02 17:27:06 -08:00) ++
meta_path = base_path + "meta.json"
+historical_path = base_path + "historical.csv.gz"
+backtesting_path = base_path + "backtesting.csv.gz"
+extrapolation_path = base_path + "extrapolation.csv.gz"
+time: 676 µs (started: 2021-12-02 17:27:07 -08:00) ++
with open(meta_path, 'r') as fid:
+ metadata = json.load(fid)
+for i, row in metadata.items():
+ print(f"{i}: {row}")
+print("---")
+createdAt: 2021-12-03 01:25:59.179791 +initial_backtesting_timestamp: 2021-05-30 21:40:11 +final_backtesting_timestamp: 2021-06-13 18:24:31 +--- +time: 2.26 ms (started: 2021-12-02 17:27:07 -08:00) ++
historical_df = pd.read_csv(historical_path).assign(origin='historical').iloc[1:].assign(subset=-1)
+backtesting_df = pd.read_csv(backtesting_path).assign(origin='backtesting').iloc[1:]
+extrapolation_df = pd.read_csv(extrapolation_path).assign(origin='extrapolation')
+
+historical_df.loc[:, 'seconds_passed'] = backtesting_df.seconds_passed
+
+past_df = (pd.concat([historical_df, backtesting_df])
+ .reset_index(drop=True)
+ .assign(seconds_passed=lambda df: df.seconds_passed - df.seconds_passed.min())
+ )
+
+extrapolation_df.loc[:, 'seconds_passed'] += past_df.seconds_passed.max()
+df = pd.concat([past_df, extrapolation_df])
+
+df = (df
+ .assign(hours_passed=lambda df: df.seconds_passed / (60 * 60))
+ .assign(days_passed=lambda df: df.seconds_passed / (24 * 60 * 60))
+ )
+
+initial_time = pd.Timestamp(metadata['initial_backtesting_timestamp'])
+deltas = df.hours_passed.map(lambda x: pd.Timedelta(x, unit='h'))
+times = initial_time + deltas
+df = df.assign(timestamp=times).reset_index()
+last_time = df.query('origin == "extrapolation"').timestamp.min()
+
+# Wrangling for extrapolation scenarios
+def extrapolation_origin(_df):
+ df = (_df.query("origin == 'extrapolation'")
+ .assign(use_ewm_model=lambda df: df.use_ewm_model.fillna(0).astype(int))
+ .assign(convergence_swap_intensity=lambda df: df.convergence_swap_intensity.fillna(0))
+ )
+ s = df.apply(lambda row: f"extrapolation (ewm={row.use_ewm_model}, csi={row.convergence_swap_intensity :.0%})", axis=1)
+ return s
+
+s = extrapolation_origin(df)
+df.loc[s.index, 'origin'] = s
+time: 72 ms (started: 2021-12-02 17:27:08 -08:00) ++
value_cols = ('eth_price', 'market_price')
+id_cols = {'timestamp', 'origin', 'subset'}
+fig_df = (df.melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'market_price': 'RAI Market Price (USD/RAI)'})
+ .replace({'eth_price': 'ETH Price (USD/RAI)'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ labels={'market_price': 'RAI Market Price in USD'},
+ title='Prices over time')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 1.99 s (started: 2021-12-02 17:27:09 -08:00) ++
In the plots above we evaluate the Eth price data (upper) and the Rai market price data (lower) showing the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +df.redemption_price.mean()
+3.0092168943492856+
time: 9.85 ms (started: 2021-12-02 17:27:14 -08:00) ++
value_cols = ('redemption_price',
+ 'redemption_rate',
+ 'redemption_rate_annual',
+ 'proportional_error',
+ 'integral_error',
+ 'derivative_error')
+id_cols = {'timestamp', 'origin', 'subset'}
+
+fig_df = (df.assign(redemption_rate_annual=lambda df: df.redemption_rate ** (24 * 365))
+ .melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'redemption_price': 'Redemption Price (USD/RAI)'})
+ .replace({'redemption_rate': 'Redemption Rate (%/hours)'})
+ .replace({'redemption_rate_annual': 'Redemption Rate (%/year)'})
+ .replace({'proportional_error': 'Proportional Error (USD/RAI)'})
+ .replace({'integral_error': 'Integral Error (USD * s / RAI)'})
+ .replace({'derivative_error': 'Derivative Error (USD * s / RAI)'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ height=1200,
+ title='Controller State over time')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 3.92 s (started: 2021-12-02 17:27:14 -08:00) ++
In the plots above we evaluate the controller states, in descending order(i.e. first state is the first plot) of redemption_price, redemption_rate, redemption_rate_annual,proportional_error, and integral_error. The plots show the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +value_cols = ('rai_debt', 'eth_locked', 'rai_reserve', 'eth_reserve')
+id_cols = {'timestamp', 'origin', 'subset'}
+fig_df = (df.melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'rai_debt': 'Global RAI Debt'})
+ .replace({'eth_locked': 'ETH Collateral'})
+ .replace({'rai_reserve': 'RAI reserve on Uniswap'})
+ .replace({'eth_reserve': 'ETH reserve on Uniswap'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ labels={'market_price': 'RAI Market Price in USD'},
+ height=900,
+ title='Token State')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 2.32 s (started: 2021-12-02 17:27:21 -08:00) ++
In the plots above we evaluate the token states, in descending order(i.e. first state is the first plot), of: rai_debt, eth_locked, rai_reserve, and eth_reserve. The plots show the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +In this report, we've shown the real historical data that flow into the DT, and then extrapolations for the potential values of these states.
+ +The Digital Twin(DT) Execution Report shows the results of a DT execution.
+ +%load_ext autotime
+time: 564 µs (started: 2021-12-02 15:43:53 -08:00) ++
import pandas as pd
+import plotly.express as px
+import json
+import os
+import plotly.offline as pyo
+pyo.init_notebook_mode()
+time: 3.54 s (started: 2021-12-02 15:43:53 -08:00) ++
base_path = "../../data/runs/2021-06-09 16:49:23.697639-"
+time: 730 µs (started: 2021-12-02 15:43:58 -08:00) ++
# Parameters
+base_path = "/Users/zcstarr/src/token_engineering/reflexer-digital-twin/data/runs/2021-12-02 23:42:09.422217-"
+time: 483 µs (started: 2021-12-02 15:43:59 -08:00) ++
meta_path = base_path + "meta.json"
+historical_path = base_path + "historical.csv.gz"
+backtesting_path = base_path + "backtesting.csv.gz"
+extrapolation_path = base_path + "extrapolation.csv.gz"
+time: 1.13 ms (started: 2021-12-02 15:44:00 -08:00) ++
with open(meta_path, 'r') as fid:
+ metadata = json.load(fid)
+for i, row in metadata.items():
+ print(f"{i}: {row}")
+print("---")
+createdAt: 2021-12-02 23:42:09.422217 +initial_backtesting_timestamp: 2021-05-30 21:40:11 +final_backtesting_timestamp: 2021-06-13 18:24:31 +--- +time: 4.28 ms (started: 2021-12-02 15:44:01 -08:00) ++
historical_df = pd.read_csv(historical_path).assign(origin='historical').iloc[1:].assign(subset=-1)
+backtesting_df = pd.read_csv(backtesting_path).assign(origin='backtesting').iloc[1:]
+extrapolation_df = pd.read_csv(extrapolation_path).assign(origin='extrapolation')
+
+historical_df.loc[:, 'seconds_passed'] = backtesting_df.seconds_passed
+
+past_df = (pd.concat([historical_df, backtesting_df])
+ .reset_index(drop=True)
+ .assign(seconds_passed=lambda df: df.seconds_passed - df.seconds_passed.min())
+ )
+
+extrapolation_df.loc[:, 'seconds_passed'] += past_df.seconds_passed.max()
+df = pd.concat([past_df, extrapolation_df])
+
+df = (df
+ .assign(hours_passed=lambda df: df.seconds_passed / (60 * 60))
+ .assign(days_passed=lambda df: df.seconds_passed / (24 * 60 * 60))
+ )
+
+initial_time = pd.Timestamp(metadata['initial_backtesting_timestamp'])
+deltas = df.hours_passed.map(lambda x: pd.Timedelta(x, unit='h'))
+times = initial_time + deltas
+df = df.assign(timestamp=times).reset_index()
+last_time = df.query('origin == "extrapolation"').timestamp.min()
+
+# Wrangling for extrapolation scenarios
+def extrapolation_origin(_df):
+ df = (_df.query("origin == 'extrapolation'")
+ .assign(use_ewm_model=lambda df: df.use_ewm_model.fillna(0).astype(int))
+ .assign(convergence_swap_intensity=lambda df: df.convergence_swap_intensity.fillna(0))
+ )
+ s = df.apply(lambda row: f"extrapolation (ewm={row.use_ewm_model}, csi={row.convergence_swap_intensity :.0%})", axis=1)
+ return s
+
+s = extrapolation_origin(df)
+df.loc[s.index, 'origin'] = s
+time: 102 ms (started: 2021-12-02 15:44:02 -08:00) ++
value_cols = ('eth_price', 'market_price')
+id_cols = {'timestamp', 'origin', 'subset'}
+fig_df = (df.melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'market_price': 'RAI Market Price (USD/RAI)'})
+ .replace({'eth_price': 'ETH Price (USD/RAI)'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ labels={'market_price': 'RAI Market Price in USD'},
+ title='Prices over time')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 2.54 s (started: 2021-12-02 15:44:03 -08:00) ++
In the plots above we evaluate the Eth price data (upper) and the Rai market price data (lower) showing the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +df.redemption_price.mean()
+3.00927009485958+
time: 8.56 ms (started: 2021-12-02 15:44:09 -08:00) ++
value_cols = ('redemption_price',
+ 'redemption_rate',
+ 'redemption_rate_annual',
+ 'proportional_error',
+ 'integral_error',
+ 'derivative_error')
+id_cols = {'timestamp', 'origin', 'subset'}
+
+fig_df = (df.assign(redemption_rate_annual=lambda df: df.redemption_rate ** (24 * 365))
+ .melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'redemption_price': 'Redemption Price (USD/RAI)'})
+ .replace({'redemption_rate': 'Redemption Rate (%/hours)'})
+ .replace({'redemption_rate_annual': 'Redemption Rate (%/year)'})
+ .replace({'proportional_error': 'Proportional Error (USD/RAI)'})
+ .replace({'integral_error': 'Integral Error (USD * s / RAI)'})
+ .replace({'derivative_error': 'Derivative Error (USD * s / RAI)'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ height=1200,
+ title='Controller State over time')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 5.99 s (started: 2021-12-02 15:44:10 -08:00) ++
In the plots above we evaluate the controller states, in descending order(i.e. first state is the first plot) of redemption_price, redemption_rate, redemption_rate_annual,proportional_error, and integral_error. The plots show the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +value_cols = ('rai_debt', 'eth_locked', 'rai_reserve', 'eth_reserve')
+id_cols = {'timestamp', 'origin', 'subset'}
+fig_df = (df.melt(id_vars=id_cols, value_vars=value_cols)
+ .replace({'rai_debt': 'Global RAI Debt'})
+ .replace({'eth_locked': 'ETH Collateral'})
+ .replace({'rai_reserve': 'RAI reserve on Uniswap'})
+ .replace({'eth_reserve': 'ETH reserve on Uniswap'})
+ )
+fig = px.line(fig_df,
+ x='timestamp',
+ y='value',
+ color='origin',
+ facet_row='variable',
+ line_group='subset',
+ labels={'market_price': 'RAI Market Price in USD'},
+ height=900,
+ title='Token State')
+fig.update_traces(line=dict(width=0.5),
+ marker=dict(opacity=0.05, size=5),
+ mode='lines+markers')
+fig.add_vline(initial_time.timestamp() * 1000,
+ annotation_text=initial_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vline(last_time.timestamp() * 1000,
+ annotation_text=last_time.strftime('%Y-%m-%d %Hh'))
+fig.add_vrect(x0=last_time,
+ x1=fig_df.timestamp.max(),
+ annotation_text="Extrapolation",
+ annotation_position="top right",
+ fillcolor="cyan",
+ opacity=0.05)
+fig.update_yaxes(matches=None)
+fig.for_each_annotation(lambda a: a.update(text=a.text.split("=")[-1]))
+fig.show()
+time: 3.84 s (started: 2021-12-02 15:44:20 -08:00) ++
In the plots above we evaluate the token states, in descending order(i.e. first state is the first plot), of: rai_debt, eth_locked, rai_reserve, and eth_reserve. The plots show the historical data and the forward extrapolation under various assumptions Exponential Moving Average (EWM) and optimal swap assumptions. The CSI number indicating the maximum intensity of the 'optimal swap'.
+ +In this report, we've shown the real historical data that flow into the DT, and then extrapolations for the potential values of these states.
+ +