Praktische use-cases
Op deze pagina
Code-uitvoering in productie
Deze laatste les behandelt praktische use-cases voor Code-uitvoering om u een duidelijk beeld te geven van wat u kunt bouwen. Elk voorbeeld illustreert een toepassingsdomein met de bijbehorende prompt en logica.
Financiële analyse
Portfolio-optimalisatie
Code-uitvoering is bij uitstek geschikt voor financiële modellering. De sandbox bevat NumPy en SciPy, die de benodigde optimalisatieberekeningen uitvoeren:
input_text = """
Portfolio of 5 assets with the following monthly returns (12 months):
Asset A: [2.1, -0.5, 1.8, 3.2, -1.1, 2.5, 0.8, 1.2, -0.3, 2.8, 1.5, 0.9]
Asset B: [1.5, 0.2, 2.1, 1.8, 0.5, 1.2, 2.3, -0.1, 1.6, 0.8, 1.9, 2.2]
Asset C: [-0.3, 3.5, -1.2, 4.1, -0.8, 2.9, -0.5, 3.2, -1.0, 3.8, -0.2, 2.7]
Asset D: [0.8, 0.9, 0.7, 1.1, 0.6, 0.8, 1.0, 0.5, 0.9, 0.7, 1.2, 0.8]
Asset E: [3.5, -2.1, 4.2, -1.5, 3.8, -0.9, 2.7, -1.8, 3.1, -0.5, 4.5, -1.2]
Calculate:
1. The correlation matrix between assets
2. The minimum variance portfolio
3. The optimal portfolio (maximum Sharpe ratio, risk-free rate = 4% annual)
4. The efficient frontier (10 points)
Present allocations as percentages.
"""
Het model schrijft code met NumPy voor de correlatiematrix en SciPy voor geoptimaliseerde berekeningen met beperkingen.
Sharpe-ratio en risicokengetallen
input_text = """
Daily returns of a fund over 20 days:
[0.12, -0.05, 0.08, 0.15, -0.03, 0.22, -0.11, 0.06, 0.09, -0.07,
0.14, 0.03, -0.08, 0.18, 0.01, -0.04, 0.11, 0.07, -0.02, 0.13]
Calculate the Sharpe ratio, Sortino ratio, Value at Risk (95%),
and maximum drawdown. Annual risk-free rate = 4%.
"""
Statistische analyse
Hypothesetoetsing
Met SciPy voert u rigoureuze statistische toetsen uit:
input_text = """
Group A (treatment): [85, 88, 91, 87, 93, 89, 86, 92, 90, 88]
Group B (control): [78, 82, 80, 85, 79, 83, 81, 77, 84, 80]
Perform a Student's t-test to determine if the difference between
the two groups is statistically significant (alpha = 0.05).
Include hypotheses, test statistic, p-value, and conclusion.
"""
Regressie en voorspelling
input_text = """
Monthly sales data (in thousands of euros):
Month (x): [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Sales (y): [45, 52, 48, 61, 55, 67, 72, 68, 75, 80, 78, 85]
1. Perform linear regression
2. Calculate R² and standard error
3. Predict sales for months 13, 14, 15
4. Test if the trend is significant
"""
Wetenschappelijk rekenen
Oplossen van differentiaalvergelijkingen
input_text = """
Solve the second-order differential equation:
y'' + 2y' + 5y = 0
Initial conditions: y(0) = 1, y'(0) = 0
Interval: t from 0 to 10
Plot the solution and identify the behavior (damped oscillation,
critical, overdamped).
"""
Monte-carlosimulaties
input_text = """
Monte Carlo simulation to estimate the probability that a project
is profitable.
Parameters (normal distributions):
- Monthly revenue: mean = €50,000, std dev = €10,000
- Monthly fixed costs: €30,000
- Variable costs: 15% to 25% of revenue (uniform)
- Project duration: 12 months
Run 10,000 simulations. Calculate the probability of profitability
and the net profit distribution. Present the 5th, 50th, and 95th percentiles.
"""
Gegevensverwerking en -schoonmaak
input_text = """
Raw data (CSV with common issues):
name,age,salary,city
Alice,32,45000,Paris
Bob,,52000,Lyon
Charlie,28,NA,Marseille
Diana,45,62000,paris
Eve,33,48000,LYON
Frank,-5,55000,Toulouse
Grace,29,999999,Bordeaux
1. Identify and handle missing values
2. Correct inconsistencies (negative age, outlier salary)
3. Normalize city names (consistent casing)
4. Calculate descriptive statistics on cleaned data
5. Document each transformation performed
"""
Complete workflow-architectuur
Voor productietoepassingen combineert u tools in een gestructureerde workflow:
- Web Search haalt actuele gegevens op (prijzen, indicatoren, nieuws)
- Code Execution analyseert de opgehaalde gegevens (berekeningen, statistieken, grafieken)
- Uw applicatie formatteert en presenteert de resultaten aan de gebruiker
Dit patroon is toepasbaar in vele domeinen: financiën, concurrentie-informatie, marktanalyse en geautomatiseerde rapportage.
Belangrijkste punten
- Code-uitvoering blinkt uit in financiële analyse (Sharpe, portfolio-optimalisatie, VaR)
- Statistische toetsen en regressies zijn een natuurlijke use-case met SciPy
- Monte-carlosimulaties werken goed binnen de geheugenlimieten van de sandbox
- Gegevensschoonmaak met Pandas is een praktische dagelijkse use-case
- Combineer Web Search + Code Execution voor complete geautomatiseerde workflows
- Lever gestructureerde gegevens en precieze instructies voor betere resultaten
Test uw kennis
Web, X, code: de servertools van Grok in vijf checks.
1. Wat zijn de twee categorieën Grok-tools?
Antwoord: Geïntegreerde tools, server-side uitgevoerd door xAI (webzoekopdracht, X-zoekopdracht, code-uitvoering), en uw aangepaste functies, uitgevoerd door uw eigen code—twee werelden die samenwerken.
2. Hoe verloopt de uitvoeringsstroom van een geïntegreerde tool?
Antwoord: In vijf server-side stappen: het model beslist, de tool wordt uitgevoerd bij xAI, resultaten keren terug naar het model, dat reageert—u ontvangt het definitieve antwoord met traces en citaten.
3. Wat maken filters voor Web Search en X Search mogelijk?
Antwoord: Bronnen afbakenen: toegestane domeinen op het web, handles en datums op X—actualiteit en betrouwbaarheid worden gecontroleerd, en citaten documenteren elk antwoord.
4. Wat kan Code Execution?
Antwoord: Python uitvoeren in een sandbox—veelgebruikte bibliotheken beschikbaar, strikte beveiligingsbeperkingen: berekeningen, transformaties en verificaties worden gedelegeerd aan exacte code.
5. Waar moet u op letten wat betreft kosten?
Antwoord: Elke tool-aanroep wordt gefactureerd bovenop de tokens: richt zoekopdrachten, beperk dieptes en activeer alleen tools die nuttig zijn voor het verzoek.
Servermogelijkheden direct klaar voor gebruik, gestuurd door uw filters en budget: geïntegreerde tools maken van Grok een agent—u blijft de regisseur.