import statsmodels.api as sm
import numpy as np
# Generate some sample data
x = np.random.rand(100)
y = 2 * x + np.random.randn(100)
# Fit a linear regression model
model = sm.OLS(y, sm.add_constant(x)).fit()
print("Regression coefficients:", model.params)
print("R-squared:", model.rsquared)
#clcoding.com
import pandas as pd
# Create a simple DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Salary': [50000, 60000, 70000]}
df = pd.DataFrame(data)
# Perform data analysis
print("DataFrame head:")
print(df.head())
print("\nAverage salary:", df['Salary'].mean())
#clcoding.com
import numpy as np
# Create a simple array
arr = np.array([1, 2, 3, 4, 5])
# Perform numerical operations
print("Sum:", np.sum(arr))
print("Mean:", np.mean(arr))
print("Standard deviation:", np.std(arr))
#clcoding.com
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
class MyWrapper(EWrapper):
def __init__(self):
super().__init__()
class MyClient(EClient):
def __init__(self, wrapper):
EClient.__init__(self, wrapper)
app = MyClient(MyWrapper())
app.connect("127.0.0.1", 7497, clientId=1)
app.run()
#clcoding.com
import numpy as np
from scipy import optimize
# Define a simple objective function
def objective(x):
return x**2 + 10*np.sin(x)
# Optimize the objective function
result = optimize.minimize(objective, x0=0)
print("Minimum value found at:", result.x)
print("Objective function value at minimum:", result.fun)
#clcoding.com
from riskfolio.Portfolio import Portfolio
# Create a simple portfolio
data = {'Asset1': [0.05, 0.1, 0.15],
'Asset2': [0.08, 0.12, 0.18],
'Asset3': [0.06, 0.11, 0.14]}
portfolio = Portfolio(returns=data)
# Perform portfolio optimization
portfolio.optimize()
print("Optimal weights:", portfolio.w)
print("Expected return:", portfolio.mu)
print("Volatility:", portfolio.sigma)
#clcoding.com
0 Comments:
Post a Comment