#!/use/bin/env python3 # Ensure environmental variables i.e. paths are set to used the modules from xf_fintech_python import DeviceManager, FDHeston import sys # State test financial model print( "\nThe Heston FD financial model\n========================================\n" ) # Declaring Variables deviceList = DeviceManager.getDeviceList( "u250") # This should could be either u200 or u250, possibly others t.b.c. sGridOutput = [] vGridOutput = [] priceGridOutput = [] lastruntime = 0 # In this example financial data to test the module is fed in via the command line. Below is an example # ./heston_fd_test.py 1.5 0.04 0.3 -0.9 0.025 1 100 200 1 200 128 64 # and the expected value output for NPV is 111.832977 # Basic checking that the number of arguments are correct if len(sys.argv) != 13: sys.exit("Incorrect number of arguments supplied - 12 expected") #Take each suffixed value and give it a meaningful name and convert from arv string format to numerical meanReversionRate_kappa = float(sys.argv[1]) longRunAveragePrice_eta = float(sys.argv[2])
#!/usr/bin/env python3 # Ensure environmental variables i.e. paths are set to the named the modules from xf_fintech_python import DeviceManager, HullWhiteAnalytic import random import sys # Basic checking that the number of arguments are correct if len(sys.argv) != 2: sys.exit("Incorrect number of arguments supplied - 1 expected - the name of the FPGA load - e.g. hwa.xclbin") # State test financial model print("\nThe HullWhiteAnalytic financial model\n=====================================\n") # Declaring Variables deviceList = DeviceManager.getDeviceList("u200") lastruntime = 0 runtime = 0 # note these values should match the generated kernel N_k0 = 16; LEN = 16; # Inputs - note that due to the random nature of the input data the output will also vary a = 0.10; sigma = 0.01; ratesList = [0.0020, 0.0050, 0.0070, 0.0110, 0.0150, 0.0180, 0.0200, 0.0220, 0.0250, 0.0288, 0.0310, 0.0340, 0.0, 0.0 ,0.0, 0.0] timesList = [0.25, 0.50, 0.75, 1.00, 1.50, 2.00, 3.00, 4.00, 5.00, 10.0, 20.0, 30.0, 0.0, 0.0, 0.0, 0.0] tList = [random.uniform(0,15) for iteration in range(LEN)] #print("tist is",tList) TList = [(random.uniform(0,15)+1+tList[iteration]) for iteration in range(LEN)] #print("TList is",TList)
"Seem to be running with the no longer supported python 2 - require version 3" ) from os.path import exists from xf_fintech_python import DeviceManager, FDHeston # Basic checking that the card and load arguments are correct if not (args.card == "u250" or args.card == "u200"): sys.exit("This version executes on either card type u200 or u250") if not exists(args.load): print("Bitstream load specified is ", args.load) sys.exit( "Please check the supplied FPGA load filename - program does not see it" ) # Declaring Variables deviceList = DeviceManager.getDeviceList( args.card) # Pass in the card type from the command line if len(deviceList) == 0: # Check at least one card found sys.exit(("Please check that you have a " + args.card + " card present and ready for use")) sGridOutput = [] vGridOutput = [] priceGridOutput = [] lastruntime = 0 # In this example financial data to test the module is fed in via the command line. Below is an example # ./heston_fd_test.py 1.5 0.04 0.3 -0.9 0.025 1 100 200 1 200 128 64 fd_heston,xclbin u200 # and the expected value output for NPV is 111.832977
inputDataList[loop].kappa = kappa inputDataList[loop].vvol = vvol inputDataList[loop].vbar = vbar print("[XF_FINTECH] ==========") print("[XF_FINTECH] Parameters") print("[XF_FINTECH] ==========") print("[XF_FINTECH] Strike price = ", K) print("[XF_FINTECH] Rho (Weiner process correlation) = ", rho) print("[XF_FINTECH] Time to maturity = ", T) print("[XF_FINTECH] Risk free interest rate = ", r) print("[XF_FINTECH] Rate of reversion (kappa) = ", kappa) print("[XF_FINTECH] volatility of volatility (sigma) = ", vvol) print("[XF_FINTECH] Long term average variance (theta) = ", vbar) deviceList = DeviceManager.getDeviceList("u250") # Look for U250 cards lastruntime = 0 # Query this implementation print("Found these {0} device(s):".format(len(deviceList))) for x in deviceList: print(x.getName()) print("Choosing the first suitable card\n") chosenDevice = deviceList[0] hestonCF = hcf(sys.argv[1]) hestonCF.claimDevice(chosenDevice) hestonCF.run(inputDataList, outputList, numberOptions) #This is the call to process contents of dataList
if not exists(args.data_in): sys.exit( "Please check the historical rates data filename - program does not see it" ) N_FACTORS = 3 MC_UN = 4 hist_data = np.loadtxt(args.data_in, delimiter=',') tenors = hist_data.shape[1] curves = hist_data.shape[0] xclbin_load = (args.xclbin_filename) # Program variables deviceList = DeviceManager.getDeviceList(args.card_type) if len(deviceList) == 0: # Check at least one card found sys.exit(("Please check that you have a " + args.card_type + " card present and ready for use")) lastruntime = 0 runtime = 0 # Identify which cards installed and choose the first available U200 card print("Found these {0} device(s):".format(len(deviceList))) for x in deviceList: print(x.getName()) chosenDevice = deviceList[0] print("Choosing the first, ", str(chosenDevice), "\n")
print("Some interact with one another; so it was decided to provide a single script") print("which walks through an example of each function from within each api module.") print("This should provide enough information, along with the example calculation scripts") print("to enable you to make use of the python functions in your own scripts.") print("\nNote: It assumes you have at least one Xilinx U series card installed") print(" and you need to have the compiled pybind module in the same directory.") print("\nWhen you are ready to continue please press the <enter> key") ; x = input() print("Starting with the DeviceManager.hpp module\n------------------------------------------") ; time.sleep(2) print("This has only one function - getDeviceList\n") ; time.sleep(2) print("This function examines the machine to see which Xilinx FPGA cards are installed.") print("The underlying C++ code does provide a degree of robustness as shown below ;") print("This function uses the 'device.hpp' library, which has a list of Xilinx card types.") print("Note: The underlying code produces some diagnostic information to stdout") print("DeviceManager.getDeviceList() will list all Xilinx cards found") deviceList = DeviceManager.getDeviceList("") print("Found these {0} device(s):".format(len(deviceList))) # Print list for x in deviceList: print(x.getName()) print('DeviceManager.getDeviceList("u200") will search for only that card type') deviceList = DeviceManager.getDeviceList("u200") print("Found these {0} device(s):".format(len(deviceList))) for x in deviceList: print(x.getName()) print('DeviceManager.getDeviceList("madeupname") will search for only that card type') deviceList = DeviceManager.getDeviceList("madeupname")