Federal Crop Insurance Quoter

To calculate insurance premiums for Yield Protection, Revenue Protection, and Revenue Protection with Harvest Price exclusion, along with their area coverage alternatives.

In [1]:
import requests
import json
import time
from pandas.io.json import json_normalize
import pandas as pd
from collections import defaultdict

API details

Request URL: https://ag-analytics.azure-api.net/FederalCropInsuranceQuoter/post

Request body

'FIPS' : The FIPS code of a county (e.g. 17019). 'CropCode': The code for a crop (e.g. corn's crop code is 41) from table A00420 of RMA ADM files. 'Type' : The code for the type of a crop (e.g. corn type grain is 16) from RMA ADM files. 'Practice': The code for the practice type of a crop (e.g. non-irrigated is 3) from RMA ADM files. Call the Practice API for available for that cfrtop 'PreventedPlanning' : An integer in the range [0, 2]. 0 = Standard, 1 = Plus 5%, 2 = Plus 1. 'UseTAYield' : int An integer in the range [0, 1]. 1 = Use Trend-Adjusted Yield, 0 = do not use Trend-Adjusted Yield. 'SharePercentage' : double A float indicating the insured share percent, in the range [0.001, 1]. 'TrendAdjustedYield' : double A double specifying the Trend-Adjusted Yield. 'Acres' : double A double specifying the acreage. 'Year' : int An integer specifying the year that the calculation should take place for. 'APHYield' : double A double specifying the Actual Production History Yield. 'Price' : double A double specifying the projected crop price. 'Volatility' : double A double specifying the volatility of the crop. ‘ReturnParameters’ : int If value is 1, parameters for the steps of the premium calculation are included in the response. If value is 0, parameters from the premium calculation are not included in the response. ‘HighRiskCode’: string Subcounty high risk code that the insured field is located in and is relevant to the specified crop, practice, and type (e.g. ‘AAA’).

In order to get Ocp-Apim-Subscription-Key, please click on this link https://analytics.ag/Session/SignInToAPIPayment

Request Parameters

In [2]:
requestbody={'FIPS':17081, 'CropCode':41, 'Type':16, 'Practice':3, 'PreventedPlanting':0, 'UseTAYield':1, 'UsePerAcre':1, 'SharePercentage':1.00, 'TrendAdjustedYield':129.88, 'Acres':44.56999969, 'Year':2019, 'APHYield':129.88, 'Price':4.00, 'Volatility':0.15, 'IncludeAdminFee':0.0}

headers={'Content-Type':'application/json',
'Ocp-Apim-Subscription-Key': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}
           

API Function

In [3]:
def post_crop_insurance_quoter(requestbody,headers):
    try:
        url = "https://ag-analytics.azure-api.net/FederalCropInsuranceQuoter/post"
     
        response = (requests.post(url,data=json.dumps(requestbody),headers=headers).text)
        
        
        response_json = json.loads(response)
        
        print(response_json)
        time.sleep(0.5)
        return response_json
    
    except Exception as e:
        raise e

Calling API Function and Displaying Response

In [4]:
crop_insurance=post_crop_insurance_quoter(requestbody,headers)
{'Premium': [[8.57, 5.83, 3.52, 6.91, 4.6, 2.78, 7.4, 5.0, 3.03], [11.62, 8.01, 4.46, 9.38, 6.26, 3.48, 10.03, 6.91, 3.84], [14.2, 10.03, 5.56, 11.53, 7.83, 4.35, 12.25, 8.57, 4.76], [19.63, 14.07, 6.87, 16.06, 10.99, 5.36, 16.87, 12.0, 5.86], [23.51, 17.25, 8.41, 19.41, 13.55, 6.62, 20.13, 14.56, 7.11], [30.56, 22.91, 11.71, 25.4, 18.17, 9.29, 26.16, 19.23, 9.83], [41.33, 31.61, 19.45, 34.64, 25.31, 15.57, 35.47, 26.45, 16.27], [60.11, 46.69, 34.57, 51.11, 38.16, 28.11, 52.05, 39.44, 29.1]], 'PremiumAllAcres': [[382.0, 260.0, 157.0, 308.0, 205.0, 124.0, 330.0, 223.0, 135.0], [518.0, 357.0, 199.0, 418.0, 279.0, 155.0, 447.0, 308.0, 171.0], [633.0, 447.0, 248.0, 514.0, 349.0, 194.0, 546.0, 382.0, 212.0], [875.0, 627.0, 306.0, 716.0, 490.0, 239.0, 752.0, 535.0, 261.0], [1048.0, 769.0, 375.0, 865.0, 604.0, 295.0, 897.0, 649.0, 317.0], [1362.0, 1021.0, 522.0, 1132.0, 810.0, 414.0, 1166.0, 857.0, 438.0], [1842.0, 1409.0, 867.0, 1544.0, 1128.0, 694.0, 1581.0, 1179.0, 725.0], [2679.0, 2081.0, 1541.0, 2278.0, 1701.0, 1253.0, 2320.0, 1758.0, 1297.0]], 'Subsidy': [[0.67, 0.8], [0.64, 0.8], [0.64, 0.8], [0.59, 0.8], [0.59, 0.8], [0.55, 0.77], [0.48, 0.68], [0.38, 0.53]], 'Liability': [[11570.0], [12729.0], [13888.0], [15047.0], [16206.0], [17364.0], [18523.0], [19682.0]], 'TotalPremium': [[25.98, 17.66, 17.66, 20.93, 13.91, 13.91, 22.46, 15.19, 15.19], [32.26, 22.28, 22.28, 26.07, 17.41, 17.41, 27.87, 19.21, 19.21], [39.47, 27.84, 27.84, 32.02, 21.74, 21.74, 34.06, 23.83, 23.83], [47.86, 34.33, 34.33, 39.2, 26.83, 26.83, 41.13, 29.28, 29.28], [57.33, 42.07, 42.07, 47.32, 33.05, 33.05, 49.11, 35.52, 35.52], [67.89, 50.91, 50.91, 56.45, 40.41, 40.41, 58.13, 42.74, 42.74], [79.49, 60.8, 60.8, 66.61, 48.69, 48.69, 68.21, 50.86, 50.86], [96.95, 75.3, 73.57, 82.45, 61.57, 59.84, 83.96, 63.63, 61.9]], 'TotalPremiumAllAcres': [[1158.0, 787.0, 787.0, 933.0, 620.0, 620.0, 1001.0, 677.0, 677.0], [1438.0, 993.0, 993.0, 1162.0, 776.0, 776.0, 1242.0, 856.0, 856.0], [1759.0, 1241.0, 1241.0, 1427.0, 969.0, 969.0, 1518.0, 1062.0, 1062.0], [2133.0, 1530.0, 1530.0, 1747.0, 1196.0, 1196.0, 1833.0, 1305.0, 1305.0], [2555.0, 1875.0, 1875.0, 2109.0, 1473.0, 1473.0, 2189.0, 1583.0, 1583.0], [3026.0, 2269.0, 2269.0, 2516.0, 1801.0, 1801.0, 2591.0, 1905.0, 1905.0], [3543.0, 2710.0, 2710.0, 2969.0, 2170.0, 2170.0, 3040.0, 2267.0, 2267.0], [4321.0, 3356.0, 3279.0, 3675.0, 2744.0, 2667.0, 3742.0, 2836.0, 2759.0]], 'SubsidyAmount': [[17.41, 11.82, 14.14, 14.02, 9.31, 11.13, 15.05, 10.19, 12.16], [20.64, 14.27, 17.81, 16.69, 11.15, 13.93, 17.84, 12.3, 15.37], [25.26, 17.81, 22.28, 20.48, 13.91, 17.39, 21.81, 15.26, 19.07], [28.23, 20.26, 27.46, 23.13, 15.84, 21.47, 24.25, 17.28, 23.42], [33.81, 24.81, 33.65, 27.91, 19.5, 26.43, 28.99, 20.96, 28.4], [37.33, 28.0, 39.2, 31.05, 22.23, 31.12, 31.97, 23.51, 32.91], [38.16, 29.19, 41.35, 31.97, 23.38, 33.12, 32.74, 24.41, 34.6], [36.84, 28.61, 38.99, 31.34, 23.4, 31.73, 31.9, 24.19, 32.8]], 'SubsidyAmountAllAcres': [[776.0, 527.0, 630.0, 625.0, 415.0, 496.0, 671.0, 454.0, 542.0], [920.0, 636.0, 794.0, 744.0, 497.0, 621.0, 795.0, 548.0, 685.0], [1126.0, 794.0, 993.0, 913.0, 620.0, 775.0, 972.0, 680.0, 850.0], [1258.0, 903.0, 1224.0, 1031.0, 706.0, 957.0, 1081.0, 770.0, 1044.0], [1507.0, 1106.0, 1500.0, 1244.0, 869.0, 1178.0, 1292.0, 934.0, 1266.0], [1664.0, 1248.0, 1747.0, 1384.0, 991.0, 1387.0, 1425.0, 1048.0, 1467.0], [1701.0, 1301.0, 1843.0, 1425.0, 1042.0, 1476.0, 1459.0, 1088.0, 1542.0], [1642.0, 1275.0, 1738.0, 1397.0, 1043.0, 1414.0, 1422.0, 1078.0, 1462.0]], 'Guarantee': [[260.0, 260.0, 64.9], [286.0, 286.0, 71.4], [312.0, 312.0, 77.9], [338.0, 338.0, 84.4], [364.0, 364.0, 90.9], [390.0, 390.0, 97.4], [416.0, 416.0, 103.9], [442.0, 442.0, 110.4]], 'CountyLevelPrem': [[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]], 'CountyLevelGuarantee': [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]], 'CountyDataAvailable': True, 'Plans': [2, 3, 6, 16, 31, 4, 1, 17, 32, 3, 2, 5, 33, 1]}
In [5]:
df=defaultdict(list)


for i in range(3):
    for value,u in zip(['Revenue Protection','Revenue Protection with Harvest Price Exclusion','Yield Protection'],['Optional','Basic','Enterprise']):
        
        df['Product Type'].append(value)
        df['Unit'].append(u)
    
coverage=['50%','55%','60%','65%','70%','75%','80%','85%']    


for k in range(9):
    for i,j in enumerate(coverage):
        
        df[j+'Premium perAcre'].append(crop_insurance['Premium'][i][k])
        df[j+'Premium totalAcre'].append(crop_insurance['PremiumAllAcres'][i][k])
        df[j+'Liability total Acre'].append(crop_insurance['Liability'][i][0])

    

df=pd.DataFrame.from_dict(df)
df
Out[5]:
Product Type Unit 50%Premium perAcre 50%Premium totalAcre 50%Liability total Acre 55%Premium perAcre 55%Premium totalAcre 55%Liability total Acre 60%Premium perAcre 60%Premium totalAcre ... 70%Liability total Acre 75%Premium perAcre 75%Premium totalAcre 75%Liability total Acre 80%Premium perAcre 80%Premium totalAcre 80%Liability total Acre 85%Premium perAcre 85%Premium totalAcre 85%Liability total Acre
0 Revenue Protection Optional 8.57 382.0 11570.0 11.62 518.0 12729.0 14.20 633.0 ... 16206.0 30.56 1362.0 17364.0 41.33 1842.0 18523.0 60.11 2679.0 19682.0
1 Revenue Protection with Harvest Price Exclusion Basic 5.83 260.0 11570.0 8.01 357.0 12729.0 10.03 447.0 ... 16206.0 22.91 1021.0 17364.0 31.61 1409.0 18523.0 46.69 2081.0 19682.0
2 Yield Protection Enterprise 3.52 157.0 11570.0 4.46 199.0 12729.0 5.56 248.0 ... 16206.0 11.71 522.0 17364.0 19.45 867.0 18523.0 34.57 1541.0 19682.0
3 Revenue Protection Optional 6.91 308.0 11570.0 9.38 418.0 12729.0 11.53 514.0 ... 16206.0 25.40 1132.0 17364.0 34.64 1544.0 18523.0 51.11 2278.0 19682.0
4 Revenue Protection with Harvest Price Exclusion Basic 4.60 205.0 11570.0 6.26 279.0 12729.0 7.83 349.0 ... 16206.0 18.17 810.0 17364.0 25.31 1128.0 18523.0 38.16 1701.0 19682.0
5 Yield Protection Enterprise 2.78 124.0 11570.0 3.48 155.0 12729.0 4.35 194.0 ... 16206.0 9.29 414.0 17364.0 15.57 694.0 18523.0 28.11 1253.0 19682.0
6 Revenue Protection Optional 7.40 330.0 11570.0 10.03 447.0 12729.0 12.25 546.0 ... 16206.0 26.16 1166.0 17364.0 35.47 1581.0 18523.0 52.05 2320.0 19682.0
7 Revenue Protection with Harvest Price Exclusion Basic 5.00 223.0 11570.0 6.91 308.0 12729.0 8.57 382.0 ... 16206.0 19.23 857.0 17364.0 26.45 1179.0 18523.0 39.44 1758.0 19682.0
8 Yield Protection Enterprise 3.03 135.0 11570.0 3.84 171.0 12729.0 4.76 212.0 ... 16206.0 9.83 438.0 17364.0 16.27 725.0 18523.0 29.10 1297.0 19682.0

9 rows × 26 columns