File: BasketOptions.py

package info (click to toggle)
stopt 5.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,860 kB
  • sloc: cpp: 70,456; python: 5,950; makefile: 72; sh: 57
file content (49 lines) | stat: -rw-r--r-- 1,475 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (C) 2016 EDF
# All Rights Reserved
# This code is published under the GNU Lesser General Public License (GNU LGPL)
import numpy as np


# call payoff for basket
class BasketCall :
    
    m_strike = 0.

    # Contructor
    # p_strike   strike
    def __init__(self, p_strike) :
        
        self.m_strike = p_strike
    
    # for one simulation, give the basket value
    # p_assets   For the current simulation values of all assets
    def apply(self, p_assets) :
        
        return np.maximum(np.mean(p_assets) - self.m_strike, np.zeros(len(p_assets.transpose())))

    # for all simulations, give the basket values
    # p_assets    values of all assets (one column is a simulation)
    def applyVec(self, p_assets) :
        
        ret = np.zeros(p_assets.shape[1])
        
        return np.maximum(np.mean(p_assets, axis=0) - self.m_strike, np.zeros(len(p_assets.transpose())))
        
# Put payoff for basket
class BasketPut :
    
    m_strike = 0.

    # Constructor
    # p_strike   strike
    def __init__(self, p_strike) :
        
        self.m_strike = p_strike

    # for all simulations, give the basket values
    # p_assets    values of all assets (one column is a simulation)
    def operator(self, p_assets) :
        
        ret = np.zeros(p_assets.shape[1])
        
        return np.maximum(-np.mean(p_assets, axis=0) + self.m_strike, np.zeros(len(p_assets.transpose())))