IMsValueAtRiskTransform.DistinguishLongShortPositions

Fore Syntax

DistinguishLongShortPositions: Boolean;

Fore.NET Syntax

DistinguishLongShortPositions: System.Boolean;

Description

The DistinguishLongShortPositions property determines whether the model should distinguish between short and long positions.

Comments

Available values:

The DistinguishLongShortPositions property is used only in the Delta-normal method, that is, IMsValueAtRiskTransform.MethodType = MsValueAtRiskMethodType.DeltaNormal.

Fore Example

Executing the example requires that the repository contains dictionaries with the identifiers:

These dictionaries are used for variable dimensions described below.

The repository should contain a modeling container with the MS_PRIMARY identifier that contains a model with the M_VAR identifier. The container should include variables with identifiers:

Add links to the Dimensions, Cubes, Metabase, Ms, Stat system assemblies.

Sub UserProc;
Var
    mb: IMetabase;
    pMsDescrKey: Integer;
    pModel: IMsModel;
    pTrans: IMsFormulaTransform;
    pInsStub, pPortStub, pVaRStub: IVariableStub;
    pOutVar, pPortVar, pInsVar: IMsFormulaTransformVariable;
    pOutSlice, pPortSlice, pInsSlice: IMsFormulaTransformSLice;
    pDimIns, pDimOrg: IDimensionModel;
    pInstIns, pInstOrg: IDimInstance;
    pSel: IDimSelection;
    pSelSet: IDimSelectionSet;
    pFactory: IDimSelectionSetFactory;
    pSelector: IMsFormulaTransformSelector;
    pFormula: IMsFOrmula;
    pVaR: IMsValueAtRiskTransform;
    pTerm: IMsFormulaTermInfo;
    pBT: IMsValueAtRiskBacktesting;
    coo: IMsFormulaTransformCoord;
    calc: IMsMethodCalculation;
    res: IMsValueAtRiskBacktestingResult;
    i: integer;
Begin
    mb := MetabaseClass.Active;
    pMsDescrKey := mb.ItemById("MS_PRIMARY").Key;
    pModel := mb.ItemByIdNamespace("M_VAR", pMsDescrKey).Edit As IMsModel;
    pTrans := pModel.Transform;
// Delete all variables from model 
    pTrans.Inputs.Clear;
    pTrans.Outputs.Clear;
    pTrans.Series.Clear;
// Set sample and forecast periods
    pModel.Period.IdentificationStartDate := DateTime.ComposeDay(200011);
    pModel.Period.IdentificationEndDate := DateTime.ComposeDay(2000110);
    pModel.Period.ForecastStartDate := DateTime.ComposeDay(2000111);
    pModel.Period.ForecastEndDate := DateTime.ComposeDay(2000120);
// Get variables for VaR model   
    pInsStub := mb.ItemByIdNamespace("V_STOCKPRICES", pMsDescrKey).Bind As IVariableStub;
    pPortStub := mb.ItemByIdNamespace("V_PORTFOLIO", pMsDescrKey).Bind As IVariableStub;
    pVaRStub := mb.ItemByIdNamespace("V_VALUEATRISK", pMsDescrKey).Bind As IVariableStub;
// Get dimension of financial tools
    pInstIns := mb.ItemById("DIM_INSTRUMENTS").Open(NullAs IDimInstance;
    pDimIns := pInstIns.Dimension;
// Get dimension of organizations
    pInstOrg := mb.ItemById("DIM_ORGANIZATIONS").Open(NullAs IDimInstance;
    pDimOrg := pInstOrg.Dimension;
// Add output variable
    pOutVar := pTrans.Outputs.Add(pVaRStub);
// Get input variable slice
    pFactory := New DimSelectionSetFactory.Create;
    pSelSet := pFactory.CreateDimSelectionSet;
    pSel := pSelSet.Add(pInstOrg);
    pSel.SelectAll;
    pOutSlice := pOutVar.Slices.Add(pSelSet);
// Add the variable of portfolio
    pPortVar := pTrans.Inputs.Add(pPortStub);
// Get the slice of portfolio
    pSelSet.Clear;
    pSel := pSelSet.Add(pInstIns);
    pSel.SelectAll;
    pSel := pSelSet.Add(pInstOrg);
    pSel.SelectAll;
    pPortSlice := pPortVar.Slices.Add(pSelSet);
//  Add variable of financial tools
    pInsVar := pTrans.Inputs.Add(pInsStub);
//  Get the slice of financial tools
    pSelSet.Clear;
    pSel := pSelSet.Add(pInstIns);
    pSel.SelectAll;
    pInsSlice := pInsVar.Slices.Add(pSelSet);
// Set model calculation method  
    pSelector := pTrans.CreateSelector;
    pSelector.Slice := pOutSlice;
    pSelector.Level := DimCalendarLevel.Day;
    pFormula := pTrans.Transform(pSelector);
    pFormula.Kind := MsFormulaKind.ValueAtRisk;
   pModel.Kind := MsModelKind.ValueAtRisk;
    pFormula.Level := DimCalendarLevel.Day;
    pVaR := pFormula.Method As IMsValueAtRiskTransform;
// Set dimensions of tools and organizations
    pVaR.InstrumentsDimension := pDimIns;
    pVaR.OrganizationsDimension := pDimOrg;
// Set "portfolio"
    pTerm := pTrans.CreateTermInfo;
    pTerm.Slice := pPortSlice;
    pVaR.Portfolio := pTerm;
// Set financial tools  
    pTerm := pTrans.CreateTermInfo;
    pTerm.Slice := pInsSlice;
    pVaR.StockPrices := pTerm;
// Set output variable   
    pTerm := pTrans.CreateTermInfo;
    pTerm.Slice := pOutSlice;
    pVaR.ValueAtRisk := pTerm;
// Specify VaR calculation method
    pVaR.MethodType := MsValueAtRiskMethodType.DeltaNormal;
// Specify confidence limit significance
    pVaR.ConfidenceLevel := 0.05;
// Set missing data treatment method
    pVaR.UseFillGaps := True;
    pVaR.MissingData.Method := MissingDataMethod.SampleAverage;
// Use logarithmic yield and zero mean hypothesis
    pVaR.LogarithmicProfit := True;
    pVaR.ZeroMean := True;
// Set forecasting horizon  
    pVaR.ForecastingHorizon := 1;
// Set up parameters of the Delta-normal method:
// Distinguish between short and long positions
    pVaR.DistinguishLongShortPositions := True;
// Set value of EMWA lambda
    pVaR.LambdaEMWA := 0.95;
// Use the random walk hypothesis
    pVaR.RandomWalk := True;
// Set backtesting VaR
    pBT := pVaR.Backtesting;
    pBT.Enabled := True;
    pBT.Observations := 10;
// Set calculation parameters 
    coo := ptrans.CreateCoord(pTrans.Outputs.Item(0));
    calc := pTrans.CreateCalculation;
    calc.Period.IdentificationStartDate := pModel.Period.IdentificationStartDate;
    calc.Period.IdentificationEndDate:=pModel.Period.IdentificationEndDate;
    calc.Period.ForecastStartDate := pModel.Period.ForecastStartDate;
    calc.Period.ForecastEndDate := pModel.Period.ForecastEndDate;
// Calculate model
    pVaR.Execute(calc, coo);
// display results
    For i := 0 To pInstOrg.Elements.Count - 1 Do
        res := pBT.Result(i);
        Debug.WriteLine("=====Organization: " + pInstOrg.Elements.Name(i) + "=======");
        If res <> Null Then
            Debug.WriteLine("Confidence level = " + res.ActualConfidenceLevel.ToString);
            Debug.WriteLine("Average uncovered risk = " + res.AverageUncoveredRisk.ToString);
            Debug.WriteLine("Average unused risk = " + res.AverageUnusedRisk.ToString);
            Debug.WriteLine("Binary loss function = " + res.BinaryLossFunction.ToString);
            Debug.WriteLine("Multiple to obtain coverage = " + res.CoveringFactor.ToString);
            Debug.WriteLine("Quadratic loss function = " + res.QuadraticLossFunction.ToString);
            Select Case res.TrafficLight
                Case MsValueAtRiskTrafficLight.Green: Debug.WriteLine("Traffic light = is green");
                Case MsValueAtRiskTrafficLight.Yellow: Debug.WriteLine("Traffic light = is yellow");
                Case MsValueAtRiskTrafficLight.Red: Debug.WriteLine("Traffic light = is red");
            End Select;
            Debug.WriteLine("Correlation between VaR and actual losses = " + res.VaRLossCorrelation.ToString);
        Else
            Debug.WriteLine("Result for organization " + i.ToString + " is empty!");
        End If;
    End For;
    (pModel As IMetabaseObject).Save;
End Sub UserProc;

After executing the example, the Value-At-Risk model is created. Parameters of model calculation are set by the Delta-normal method. Model calculation results are displayed in the console window.

See also:

IMsValueAtRiskTransform