from app.main.data_management.data_base import *


class FEPosition(Schema.base):
    __tablename__ = 'fe_position'

    id = Column(INTEGER(11), primary_key=True, nullable=False)
    asset_id = Column(ForeignKey('fe_asset.id'), nullable=False, index=True)
    portfolio_id = Column(ForeignKey('fe_portfolio.id'), nullable=False, index=True)
    market_date = Column(DateTime)
    quantity = Column(INTEGER)
    price = Column(Float) # prix moyen pondéré
    close_price = Column(Float)
    variation = Column(Float)
    valuation = Column(Float)
    profit_and_loss = Column(Float)
    volatility = Column(Float)
    var95 = Column(Float)
    var99 = Column(Float)
    weight = Column(Float)
    asset = relationship('FEAsset')
    portfolio = relationship('FEPortfolio')

    def __init__(self, asset_id, portfolio_id, market_date, quantity, price, variation, valuation, profit_and_loss,
                 volatility, var95, var99, weight, close_price):
        self.asset_id = asset_id
        self.portfolio_id = portfolio_id
        self.quantity = quantity
        self.price = price
        self.market_date = market_date
        self.variation = variation
        self.valuation = valuation
        self.profit_and_loss = profit_and_loss
        self.volatility = volatility
        self.var95 = var95
        self.var99 = var99
        self.weight = weight
        self.close_price = close_price

    def clone(self, new_market_date):
        return FEPosition(self.asset_id, self.portfolio_id, new_market_date, self.quantity, self.price, self.variation,
                          self.valuation, self.profit_and_loss, self.volatility, self.var95, self.var99, self.weight,
                          self.close_price)