Create a portfolio by combining alphas created by yourself or others
Importing Libraries
Here, necessary libraries are imported for the operation of the portfolio model.
import numpy as np
from finter import BasePortfolio
Define Model Information
# Model information configuration
model_info = {
"exchange": "krx", # Exchange name, e.g., Korean Exchange (KRX)
"universe": "krx", # Universe for the model
"instrument_type": "stock", # Type of instrument, e.g., stock
"freq": "1d", # Frequency of data, e.g., daily (1d)
"position_type": "target", # Type of position, e.g., target
"type": "portfolio" # Model type, e.g., alpha
}
Alpha List Definition
A list of alphas for the portfolio is defined. These alphas are specific financial models or strategies to be used within the portfolio. alpha_list replaces the functionality of the deprecated alpha_set.
A Portfolio class is defined, inheriting from BasePortfolio. It includes methods for loading alpha positions for a given period and fetching alpha positions to construct the portfolio.
from finter.framework_model.simulation import adj_stat_container_helper
# Generating model statistics
model_stat = adj_stat_container_helper(
position=pf, # Portfolio position data
model_info=model_info, # Model information defined above
start=start, # Start date for the simulation
end=end, # End date for the simulation
volcap_pct=1, # Volume cap percentage
decay=1, # Decay factor for volume limit
cost_list=["hi_low", "fee_tax"], # Costs to include (price limits, transaction tax)
slippage=10, # Slippage applied (10 basis points)
return_calc_method="geometric", # Method for return calculation (geometric)
turnover_calc_method="diff", # Method for turnover calculation (diff)
booksize=1e8, # Size of the book (100 million)
close=True, # Whether to use closing prices
adj_dividend=False # Apply dividend adjustments
)
import pandas as pd
df = pd.read_json(model_stat['cum_ret'], orient='records').set_index('index')['data']
df.index = pd.to_datetime(df.index).to_series().apply(lambda x: x.date())
df.plot()