QFL: Quant F#in Lib


Module with Autocall definition

    type State =
        {
            mutable CouponMemory:float 
            ///required field containing cash flows
            mutable CashFlow:Instrument.CashFlow
            mutable CouponDateIndex:int
            mutable FundingDateIndex:int
            mutable IsAutocalled:bool
            mutable Probability:float list
        
        } with member this.Clone = {this with CashFlow = this.CashFlow} 

Instrument parameters

    type Data = 
        {
            AssetNames: string []
            CouponDates:DateTime []
            CouponPayDates:DateTime []            

            FundingDates:DateTime []
            FundingPayDates:DateTime []            
        
            InitialLevels: float []
            CouponTriggerLevel:float
            Coupon:float
            FundingRate:float
            Notional:float
            Currency:Currency
            PutGearing:float
            Strike:float
            AutocallTriggerLevel:float
        } 

Instrument payoff definition

    let payoff instrument date state spots =
 
         if  instrument.CouponDates|>Array.contains date   then   
     
             let isNotAutocalled = if state.IsAutocalled then 0. else 1.
             let worst =  Array.map2 (fun x y -> x/y) spots instrument.InitialLevels |>Array.min                        

             let currCpTrig = if worst - instrument.CouponTriggerLevel > 0. then 1. else 0.
 
             let flow = isNotAutocalled*currCpTrig*(instrument.Coupon + state.CouponMemory)*instrument.Notional*0.25                     

             let cpn = cash flow instrument.CouponPayDates.[state.CouponDateIndex] instrument.Currency
 
             let isAutocalled = if worst >= instrument.AutocallTriggerLevel then true else state.IsAutocalled

             let prob = if isAutocalled = state.IsAutocalled then 0. else 1.
     
             state.CouponMemory <- (instrument.Coupon + state.CouponMemory) * (1. - currCpTrig)
             state.IsAutocalled <- isAutocalled

             state.CouponDateIndex <- state.CouponDateIndex + 1
             state.Probability     <- prob :: state.Probability
             state.CashFlow        <- cpn :: state.CashFlow 

             if date = Array.last instrument.CouponDates then 
                 let flow = -isNotAutocalled*instrument.PutGearing*Math.Max(0.,instrument.Strike - worst)*instrument.Notional
                 let put = cash flow date  instrument.Currency   
                 state.CashFlow <- put::state.CashFlow 

         if  instrument.FundingDates|>Array.contains date then
     
              let funding = instrument.Notional*0.25*instrument.FundingRate*if state.IsAutocalled then 0. else 1.
              let cash = cash -funding instrument.FundingPayDates.[state.FundingDateIndex]   instrument.Currency
              state.CashFlow <- cash::state.CashFlow
              state.FundingDateIndex <- state.FundingDateIndex + 1

         state
namespace System
namespace QFL
namespace QFL.MonteCarlo
module Instrument from QFL.MonteCarlo
module Autocall from AutocallScript
val step: x: float -> float
val x: float
State.CouponMemory: float
Multiple items
val float: value: 'T -> float (requires member op_Explicit)
<summary>Converts the argument to 64-bit float. This is a direct conversion for all primitive numeric types. For strings, the input is converted using <c>Double.Parse()</c> with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted float</returns>


--------------------
[<Struct>] type float = Double
<summary>An abbreviation for the CLI type <see cref="T:System.Double" />.</summary>
<category>Basic Types</category>


--------------------
type float<'Measure> = float
<summary>The type of double-precision floating point numbers, annotated with a unit of measure. The unit of measure is erased in compiled code and when values of this type are analyzed using reflection. The type is representationally equivalent to <see cref="T:System.Double" />.</summary>
<category index="6">Basic Types with Units of Measure</category>
Multiple items
State.CashFlow: CashFlow
required field containing cash flows

--------------------
type CashFlow = Cash list
type CashFlow = Cash list
State.CouponDateIndex: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
<summary>Converts the argument to signed 32-bit integer. This is a direct conversion for all primitive numeric types. For strings, the input is converted using <c>Int32.Parse()</c> with InvariantCulture settings. Otherwise the operation requires an appropriate static conversion method on the input type.</summary>
<param name="value">The input value.</param>
<returns>The converted int</returns>


--------------------
[<Struct>] type int = int32
<summary>An abbreviation for the CLI type <see cref="T:System.Int32" />.</summary>
<category>Basic Types</category>


--------------------
type int<'Measure> = int
<summary>The type of 32-bit signed integer numbers, annotated with a unit of measure. The unit of measure is erased in compiled code and when values of this type are analyzed using reflection. The type is representationally equivalent to <see cref="T:System.Int32" />.</summary>
<category>Basic Types with Units of Measure</category>
State.FundingDateIndex: int
State.IsAutocalled: bool
[<Struct>] type bool = Boolean
<summary>An abbreviation for the CLI type <see cref="T:System.Boolean" />.</summary>
<category>Basic Types</category>
State.Probability: float list
type 'T list = List<'T>
<summary>The type of immutable singly-linked lists. </summary>
<remarks>See the <see cref="T:Microsoft.FSharp.Collections.ListModule" /> module for further operations related to lists. Use the constructors <c>[]</c> and <c>::</c> (infix) to create values of this type, or the notation <c>[1; 2; 3]</c>. Use the values in the <c>List</c> module to manipulate values of this type, or pattern match against the values directly. See also <a href="https://docs.microsoft.com/dotnet/fsharp/language-reference/lists">F# Language Guide - Lists</a>. </remarks>
val this: State
State.CashFlow: CashFlow
required field containing cash flows
Multiple items
namespace System.Data

--------------------
namespace Microsoft.FSharp.Data

--------------------
type Data = { AssetNames: string[] CouponDates: DateTime[] CouponPayDates: DateTime[] FundingDates: DateTime[] FundingPayDates: DateTime[] InitialLevels: float[] CouponTriggerLevel: float Coupon: float FundingRate: float Notional: float ... }
Data.AssetNames: string[]
Multiple items
val string: value: 'T -> string
<summary>Converts the argument to a string using <c>ToString</c>.</summary>
<remarks>For standard integer and floating point values the and any type that implements <c>IFormattable</c><c>ToString</c> conversion uses <c>CultureInfo.InvariantCulture</c>. </remarks>
<param name="value">The input value.</param>
<returns>The converted string.</returns>


--------------------
type string = String
<summary>An abbreviation for the CLI type <see cref="T:System.String" />.</summary>
<category>Basic Types</category>
Data.CouponDates: DateTime[]
Multiple items
[<Struct>] type DateTime = new: year: int * month: int * day: int -> unit + 10 overloads member Add: value: TimeSpan -> DateTime member AddDays: value: float -> DateTime member AddHours: value: float -> DateTime member AddMilliseconds: value: float -> DateTime member AddMinutes: value: float -> DateTime member AddMonths: months: int -> DateTime member AddSeconds: value: float -> DateTime member AddTicks: value: int64 -> DateTime member AddYears: value: int -> DateTime ...
<summary>Represents an instant in time, typically expressed as a date and time of day.</summary>

--------------------
DateTime ()
   (+0 other overloads)
DateTime(ticks: int64) : DateTime
   (+0 other overloads)
DateTime(ticks: int64, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, calendar: Globalization.Calendar) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int) : DateTime
   (+0 other overloads)
DateTime(year: int, month: int, day: int, hour: int, minute: int, second: int, millisecond: int, kind: DateTimeKind) : DateTime
   (+0 other overloads)
Data.CouponPayDates: DateTime[]
Data.FundingDates: DateTime[]
Data.FundingPayDates: DateTime[]
Data.InitialLevels: float[]
Data.CouponTriggerLevel: float
Data.Coupon: float
Data.FundingRate: float
Data.Notional: float
Multiple items
Data.Currency: Currency

--------------------
type Currency = | RUB | USD | EUR | GBP | CHF | XAU | JPY | CNH | TRY | RON ... override ToString: unit -> string static member FromString: s: string -> Currency option
type Currency = | RUB | USD | EUR | GBP | CHF | XAU | JPY | CNH | TRY | RON ... override ToString: unit -> string static member FromString: s: string -> Currency option
Data.PutGearing: float
Data.Strike: float
Data.AutocallTriggerLevel: float
val payoff: instrument: Data -> date: DateTime -> state: State -> spots: float[] -> State
val instrument: Data
val date: DateTime
val state: State
val spots: float[]
type Array = interface ICollection interface IEnumerable interface IList interface IStructuralComparable interface IStructuralEquatable interface ICloneable member Clone: unit -> obj member CopyTo: array: Array * index: int -> unit + 1 overload member GetEnumerator: unit -> IEnumerator member GetLength: dimension: int -> int ...
<summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary>
val contains: value: 'T -> array: 'T[] -> bool (requires equality)
<summary>Tests if the array contains the specified element.</summary>
<param name="value">The value to locate in the input array.</param>
<param name="array">The input array.</param>
<returns>True if the input array contains the specified element; false otherwise.</returns>
<exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
val isNotAutocalled: float
val worst: float
val map2: mapping: ('T1 -> 'T2 -> 'U) -> array1: 'T1[] -> array2: 'T2[] -> 'U[]
<summary>Builds a new collection whose elements are the results of applying the given function to the corresponding elements of the two collections pairwise. The two input arrays must have the same lengths, otherwise an <c>ArgumentException</c> is raised.</summary>
<param name="mapping">The function to transform the pairs of the input elements.</param>
<param name="array1">The first input array.</param>
<param name="array2">The second input array.</param>
<exception cref="T:System.ArgumentException">Thrown when the input arrays differ in length.</exception>
<exception cref="T:System.ArgumentNullException">Thrown when either of the input arrays is null.</exception>
<returns>The array of transformed elements.</returns>
val y: float
val min: array: 'T[] -> 'T (requires comparison)
<summary>Returns the lowest of all elements of the array, compared via Operators.min.</summary>
<remarks>Throws ArgumentException for empty arrays</remarks>
<param name="array">The input array.</param>
<exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
<exception cref="T:System.ArgumentException">Thrown when the input array is empty.</exception>
<returns>The minimum element.</returns>
val currCpTrig: float
val flow: float
val cpn: Cash
val cash: amount: float -> date: DateTime -> currency: Currency -> Cash
Data.Currency: Currency
val isAutocalled: bool
val prob: float
val last: array: 'T[] -> 'T
<summary>Returns the last element of the array.</summary>
<param name="array">The input array.</param>
<returns>The last element of the array.</returns>
<exception cref="T:System.ArgumentNullException">Thrown when the input array is null.</exception>
<exception cref="T:System.ArgumentException">Thrown when the input does not have any elements.</exception>
type Math = static member Abs: value: decimal -> decimal + 7 overloads static member Acos: d: float -> float static member Acosh: d: float -> float static member Asin: d: float -> float static member Asinh: d: float -> float static member Atan: d: float -> float static member Atan2: y: float * x: float -> float static member Atanh: d: float -> float static member BigMul: a: int * b: int -> int64 + 2 overloads static member BitDecrement: x: float -> float ...
<summary>Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.</summary>
Math.Max(val1: unativeint, val2: unativeint) : unativeint
   (+0 other overloads)
Math.Max(val1: uint64, val2: uint64) : uint64
   (+0 other overloads)
Math.Max(val1: uint32, val2: uint32) : uint32
   (+0 other overloads)
Math.Max(val1: uint16, val2: uint16) : uint16
   (+0 other overloads)
Math.Max(val1: float32, val2: float32) : float32
   (+0 other overloads)
Math.Max(val1: sbyte, val2: sbyte) : sbyte
   (+0 other overloads)
Math.Max(val1: nativeint, val2: nativeint) : nativeint
   (+0 other overloads)
Math.Max(val1: int64, val2: int64) : int64
   (+0 other overloads)
Math.Max(val1: int, val2: int) : int
   (+0 other overloads)
Math.Max(val1: int16, val2: int16) : int16
   (+0 other overloads)
val put: Cash
val funding: float
val cash: Cash
Multiple items
module Instrument from QFL.MonteCarlo

--------------------
type Instrument = interface IPayoffInstrument<State,float[]> new: x: Data -> Instrument

--------------------
new: x: Data -> Instrument
val x: Data
type IPayoffInstrument<'State,'ProcessState> = abstract evolve: date: DateTime -> 'State -> 'ProcessState -> 'State abstract Dates: DateTime[] abstract assetNames: string[] abstract initialState: 'State
type State = { mutable CouponMemory: float mutable CashFlow: CashFlow mutable CouponDateIndex: int mutable FundingDateIndex: int mutable IsAutocalled: bool mutable Probability: float list } member Clone: State
val this: Instrument
val concat: arrays: seq<'T[]> -> 'T[]
<summary>Builds a new array that contains the elements of each of the given sequence of arrays.</summary>
<param name="arrays">The input sequence of arrays.</param>
<returns>The concatenation of the sequence of input arrays.</returns>
<exception cref="T:System.ArgumentNullException">Thrown when the input sequence is null.</exception>
val spot: float[]